home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Meeting Pearls 1
/
Meeting Pearls Vol 1 (1994).iso
/
amok98-106
/
amok103
/
identifiedtypes
/
identifiedtypestest.mod
< prev
next >
Wrap
Text File
|
1993-12-05
|
4KB
|
160 lines
MODULE IdentifiedTypesTest;
IMPORT SYSTEM,
I:=IdentifiedTypes,
L:=ComplexLists,
F:=FileSystem,
io,
NoGuru;
(* $TypeChk+ $NilChk+ $ReturnChk+ *)
TYPE Name = POINTER TO NameDesc;
NameExt = POINTER TO NameExtDesc;
NameDesc = RECORD (L.NodeDesc)
name: ARRAY 28 OF CHAR;
END;
NameExtDesc = RECORD (NameDesc)
data: POINTER TO ARRAY OF CHAR;
END;
VAR nameList : L.List;
dupList : L.List;
i : I.IDENT;
name : Name;
nameext : NameExt;
cnt: INTEGER;
z: CHAR;
f: F.File;
PROCEDURE CreateNameExt*(): I.IDENT;
VAR ne: NameExt;
BEGIN
NEW(ne); NEW(ne.data,16);
RETURN ne;
END CreateNameExt;
PROCEDURE (n: Name) Write*(VAR f: F.File): BOOLEAN;
BEGIN
RETURN n.Write^(f) AND
F.WriteString(f,n.name);
END Write;
PROCEDURE (n: Name) Read*(VAR f: F.File): BOOLEAN;
BEGIN
RETURN n.Read^(f) AND
F.ReadString(f,n.name);
END Read;
PROCEDURE (n: Name) Copy*(x: I.IDENT);
BEGIN
n.Copy^(x);
WITH x: Name DO
x.name:=n.name;
ELSE
END;
END Copy;
PROCEDURE (ne: NameExt) Write*(VAR f: F.File): BOOLEAN;
BEGIN
RETURN ne.Write^(f) AND
F.WriteString(f,ne.data^);
END Write;
PROCEDURE (ne: NameExt) Read*(VAR f: F.File): BOOLEAN;
BEGIN
RETURN ne.Read^(f) AND
F.ReadString(f,ne.data^);
END Read;
PROCEDURE (ne: NameExt) Copy*(x: I.IDENT);
BEGIN
ne.Copy^(x);
WITH x: NameExt DO
COPY(ne.data^,x.data^);
ELSE
END;
END Copy;
BEGIN
nameList:=L.Create();
NEW(name);
nameext:=CreateNameExt()(NameExt);
IF (I.AddAutoCreateType("NAME",name)=NIL) OR
(I.AddManualCreateType("NAMEEXT",SYSTEM.TYPEDESC(NameExtDesc),CreateNameExt)=NIL) THEN
io.WriteString("Typinitialisierungsfehler!\n"); HALT(20);
END;
name.name:="name";
nameext.name:="nameext"; nameext.data^:="nameextdata";
FOR cnt:=1 TO 32 DO (* 64 Datensätze *)
nameList.Add(name.Duplicate()(L.Node));
nameList.Add(nameext.Duplicate()(L.Node));
END;
IF nameList.Test()#-1 THEN io.WriteString("Fehler in Listenstruktur!(name)"); HALT(20) END;
IF ~F.Open(f,"ram:testfile",TRUE) OR
~nameList.Write(f) OR
~F.Close(f) THEN
io.WriteString("Fehler bei Zugriff auf Datei\n");
END;
IF F.Open(f,"ram:testfile",FALSE) THEN
i:=I.ReadNext(f);
IF (i#NIL) AND (i IS L.List) THEN
dupList:=i(L.List);
ELSE
io.WriteString("Fehler in Dateistruktur oder bei Read\n");
END;
END;
IF dupList.Test()#-1 THEN io.WriteString("Fehler in Listenstruktur!(dup)"); HALT(20) END;
IF ~F.Open(f,"ram:testfile2",TRUE) OR
~dupList.Write(f) OR
~F.Close(f) THEN
io.WriteString("Fehler bei Zugriff auf Datei\n");
END;
io.WriteString("Dateien ram:testfile und ram:testfile2 sollten identisch sein\n");
FOR cnt:=64 TO 1 BY -3 DO (* entfernt 1/3 der Datensätze *)
i:=nameList.Goto(cnt);
i(L.Node).Remove;
END;
IF dupList.Test()#-1 THEN io.WriteString("Fehler in Listenstruktur!(dup)"); HALT(20) END;
IF ~F.Open(f,"ram:testfile3",TRUE) OR
~nameList.Write(f) OR
~F.Close(f) THEN
io.WriteString("Fehler bei Zugriff auf Datei\n");
END;
io.WriteString("Datei ram:testfile3 sollte 22 Datensätze weniger enthalten\n");
dupList:=nameList.Duplicate()(L.List);
IF dupList.Test()#-1 THEN io.WriteString("Fehler in Listenstruktur!(dup)"); HALT(20) END;
IF ~F.Open(f,"ram:testfile4",TRUE) OR
~dupList.Write(f) OR
~F.Close(f) THEN
io.WriteString("Fehler bei Zugriff auf Datei\n");
END;
io.WriteString("Dateien ram:testfile3 und ram:testfile4 sollten identisch sein\n");
CLOSE
io.Read(z);
END IdentifiedTypesTest.